#pragma once

#include "Base Object.h"
#include "Space.h"

//Used to hold materials such as iron, sulfur and gems
#include "ResourceBag.h"
//Used to hold all items such as pickaxe, and tnt
#include "Inventory.h"


class Player : public BaseObject
{
private:
	Space* CurrentSpace;
	Space* MovingTo;
	Inventory MyItems;
	ResourceBag* MyResources;
	int Score;
	int SpacesToMove;
	bool m_bMoving;
public:
	Player(eTextureIndex T):Score(0)
	{
		BaseObject();
		textureIndex = T;
		CurrentSpace = NULL;
		SpacesToMove = 0;
		m_bMoving = false;
		MyResources = new ResourceBag();
	}

	void Update(float DeltaT);

	const FunctionReturn Move(int Dir);

	const FunctionReturn Step(float DeltaT);

	const FunctionReturn Move(eTileType MAT);

	const bool IfMoving(){return m_bMoving;}

	const bool IfAtEnd();

	inline const int GetIron()
	{
		return MyResources->CheckIron();
	}

	inline const int GetSulfur()
	{
		return MyResources->CheckSulfur();
	}

	inline const int GetGem()
	{
		return MyResources->CheckGem();
	}

	inline const FunctionReturn SetCurrentSpace(Space* S)
	{
		CurrentSpace = S;
		MovingTo = CurrentSpace;
		m_vPosition = CurrentSpace->m_vPosition;
		return SUCCEED;
	}

	inline const FunctionReturn SetTextIndex(eTextureIndex T)
	{
		textureIndex = T;
		return SUCCEED;
	}

	//if the item can be used it attempts to use it, the player and the type of object
	// must be passed to inventorys use function
	// All items affect the player and the inventory must know what item to use
	// if the item cannot be used it returns fail
	inline const FunctionReturn UseItem(eItemType TYPE)
	{
		RETURN_CHECK( Construct(TYPE) );
		if(MyItems.IfUsable(TYPE))
		{
			RETURN_CHECK( MyItems.Use((BaseObject*)this,TYPE) );
			return SUCCEED;
		}
		return FAIL;
	}

	//If the Items canmakeitem function returns succeed
	// then the item is set to enabled through the add item function
	inline const FunctionReturn Construct(eItemType TYPE)
	{
		if(CanMakeObject[TYPE](MyResources) == SUCCEED)
		{
			RETURN_CHECK( MyItems.AddItem(TYPE) );
			return SUCCEED;
		}
		return FAIL;
	}

	//Pass in the amount of materials A
	//Pass in the type of material Mat
	// MAT_IRON,MAT_SULFUR,MAT_GEM
	inline const FunctionReturn AddMaterial(eInvMaterials Mat,int A)
	{
		switch(Mat)
		{
		case 0: MyResources->AddIron(A); break;
		case 1: MyResources->AddSulfur(A); break;
		case 2: MyResources->AddGem(A); break;
		default:return UNKNOWN;
		}
		return SUCCEED;
	}
};

